//
//  userDetaislInfoView.m
//  NiubilityProject
//
//  Created by Apple on 2017/11/29.
//  Copyright © 2017年 Apple. All rights reserved.
//

#import "userDetaislInfoView.h"
#import "userInfoTitleView.h"
#import "QMUIFloatLayoutView+JSHander.h"
#import "JSCountryInfoModel.h"

@interface userDetaislInfoView ()

@property (nonatomic, strong) QMUIFloatLayoutView *floatLayoutView;
@property (nonatomic, strong) NSMutableArray *titleLables;
@property (nonatomic, strong) UILabel *titleDescL;
@property (nonatomic, weak) YYLabel *titleL1;
@property (nonatomic, weak) YYLabel *titleL2;
@property (nonatomic, weak) UIView *linev;

@end

@implementation userDetaislInfoView

- (instancetype)init{
    if (self = [super init]) {
        _titleLables = @[].mutableCopy;
        CGFloat margin10 = kRealValue(10);
        // title
        YYLabel *titleL1 = [YYLabel new];
        self.titleL1 = titleL1;
        titleL1.text = JSLocalizedString(@"Personalinformation");
        JSSetingLableInfo(titleL1, 13, JS_colorWithHex(kColorBlack3));
        [self addSubview:titleL1];
       
        NSArray *titles = @[JSLocalizedString(@"countryLoca"),JSLocalizedString(@"cityLoca"),JSLocalizedString(@"genderLoca")];
        NSArray *contens= @[@"",@"",@""];
        
        self.floatLayoutView = [[QMUIFloatLayoutView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0)];
        [self addSubview:self.floatLayoutView];
       
        self.floatLayoutView.padding = UIEdgeInsetsMake(0, margin10, 0, margin10);
        self.floatLayoutView.itemMargins = UIEdgeInsetsMake(0, 0, 10, 10);
        self.floatLayoutView.minimumItemSize = CGSizeMake(69, 29);
        for (NSInteger i = 0; i < titles.count; i ++) {
            NSString *title = titles[i];
            NSString *conten= contens[i];
            userInfoTitleView *titleView = [userInfoTitleView new];
            titleView.titleL.text = title;
            titleView.contenL.text= conten;
            [self.floatLayoutView addSubview:titleView];
            [self.titleLables addObject:titleView];
        }
        
        UIView *lineV = [UIView new];
        self.linev = lineV;
        lineV.backgroundColor = JS_colorWithHex(0xf7f7f7);
        [self addSubview:lineV];
        
        YYLabel *titleL2 = [YYLabel new];
        self.titleL2 = titleL2;
        titleL2.text = JSLocalizedString(@"Individualitysignature");
        JSSetingLableInfo(titleL2, 13, JS_colorWithHex(kColorBlack3));
        [self addSubview:titleL2];
       
        
        UILabel *titleDescL = [UILabel new];
        self.titleDescL = titleDescL;
        JSSetingLableInfo(titleDescL, 13, JS_colorWithHex(kColorBlack3));
        titleDescL.numberOfLines = 0;
        titleDescL.textAlignment = NSTextAlignmentCenter;
        titleDescL.lineBreakMode = NSLineBreakByCharWrapping;
        [self addSubview:titleDescL];
    }
    return self;
}
- (void)updateConstraints{
    JS_WeakSelf(self)
    CGFloat margin10 = kRealValue(10);
    [self.titleL1 mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakself).offset(margin10);
        make.top.equalTo(weakself).offset(margin10);
    }];
    [self.floatLayoutView mas_updateConstraints:^(MASConstraintMaker *make) {            make.top.equalTo(self.titleL1.mas_bottom).offset(margin10);            make.left.and.right.equalTo(weakself);        }];
    [self.floatLayoutView mas_updateConstraints:^(MASConstraintMaker *make) {            make.height.mas_equalTo([weakself.floatLayoutView js_getContentSize:CGSizeMake(SCREEN_WIDTH, 0)].height);        }];
    [self.linev mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.and.right.equalTo(self);
        make.top.equalTo(weakself.floatLayoutView.mas_bottom);
        make.height.mas_equalTo(2);
    }];
    [self.titleL2 mas_updateConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.linev.mas_bottom).offset(margin10);
        make.left.equalTo(self.titleL1);
        make.height.mas_equalTo(17);
    }];
    [self.titleDescL mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleL1);
        make.right.equalTo(self).offset(-margin10);
        make.top.equalTo(self.titleL2.mas_bottom).offset(margin10);
    }];
    [self mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.equalTo(self.titleDescL.mas_bottom).offset(margin10);
    }];
    [super updateConstraints];
    
}
- (void)setUserInfol:(UserInfo *)userInfol{
    _userInfol = userInfol;
    userInfoTitleView *countryTitleV = self.titleLables[0];
    userInfoTitleView *cityTitleV = self.titleLables[1];
    userInfoTitleView *genderTitleV = self.titleLables[2];
    if (JSLocalizeIsChina()) {
        
    }else{
        
    }
    countryTitleV.contenL.text = JSLocalizeIsChina()?userInfol.city.country_zh:userInfol.city.country;
    cityTitleV.contenL.text = JSLocalizeIsChina()?userInfol.city.state_zh:userInfol.city.state;
    genderTitleV.contenL.text = userInfol.sex == UserGenderMale ? JSLocalizedString(@"genderMan"):JSLocalizedString(@"genderWoman");
    self.titleDescL.text = userInfol.mood.length?userInfol.mood:JSLocalizedString(@"TemporarilyNoData");
    // 告诉self.view约束需要更新
    [self setNeedsUpdateConstraints];
    // 调用此方法告诉self.view检测是否需要更新约束，若需要则更新，下面添加动画效果才起作用
    [self updateConstraintsIfNeeded];
    [self layoutIfNeeded];
    
}
@end
